package cn.tedu.nybikeT.controller;

import java.util.List;
import java.io.Console;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.tedu.nybikeT.pojo.InOutVO;
import cn.tedu.nybikeT.pojo.JsonResult;
import cn.tedu.nybikeT.pojo.PopularStationVO;
import cn.tedu.nybikeT.pojo.StationSecurityVO;
import cn.tedu.nybikeT.pojo.TopBikeVO;
import cn.tedu.nybikeT.pojo.TripByUserVO;
import cn.tedu.nybikeT.service.IDataAnalysisService;

@RestController // 表示本类中所有方法返回的都是json字符串
@RequestMapping("/dataanalysis")
public class DataAnalysisController {

	@Autowired
	IDataAnalysisService service;

	// Rory
	@RequestMapping("/stationsecurity")
	public JsonResult<List<StationSecurityVO>> getStationSecurityData(int year, int month, float radius) {
		JsonResult<List<StationSecurityVO>> jr = new JsonResult<>();

		// 判断参数是否正确
		if (year < 2013 || year > 2020 || month < 0 || month > 12 || radius <= 0 || radius > 1) {
			jr.setState(5001);
			jr.setMsg("参数错误!");
			return jr;
		}

		List<StationSecurityVO> voList = service.countStationSecurity(year, month, radius);
		jr.setState(2000);
		jr.setMsg("OK");
		jr.setData(voList);
		return jr;
	}
	// End

	// hk

	// End

	// late-whale

	// End

	// Asia
	@RequestMapping("/getTopBikeAsia")
	public JsonResult<TopBikeVO> gettopbike() {

		TopBikeVO vo = service.listGetTopBike();
		JsonResult jr = new JsonResult();
		jr.setState(2000);
		jr.setMsg("OK");
		jr.setData(vo);
		//System.out.println(vo.tripduration+"--");
		//System.out.println(vo.bikeid);
		return jr;
	}
	
	@RequestMapping("/getUserType")
	public JsonResult<TripByUserVO> getuser() {

		TripByUserVO vo = service.listTripUserType();
		JsonResult jr = new JsonResult();
		jr.setState(2000);
		jr.setMsg("OK");
		jr.setData(vo);
		//System.out.println(vo.tripduration+"--");
		//System.out.println(vo.bikeid);
		return jr;
	}
	// End

	// LRY
	@RequestMapping("/popular")
	public JsonResult<PopularStationVO> Popular(Integer topStationCountLimit, Integer lastStationCountLimit) {

		PopularStationVO vo = service.findPopularStationData(topStationCountLimit, lastStationCountLimit);
		JsonResult jr = new JsonResult();
		jr.setState(2000);
		jr.setMsg("OK");
		jr.setData(vo);
		return jr;
	}

	@RequestMapping("/inout")
	public JsonResult<InOutVO> InOut(Integer stationCountLimit) {

		InOutVO vo = service.findStationCountData(stationCountLimit);
		JsonResult jr = new JsonResult();
		jr.setState(2000);
		jr.setMsg("OK");
		jr.setData(vo);
		return jr;
	}
	// End

}
